$(function(){

    var admin_id = getCookie('admin_id');
    if(!admin_id){
        window.location.replace('login.html');
    }

    $.ajax({

        url: ApiUrl + "/taocang?limit="+Page,
        type: 'get',
        dataType: 'JSON',
        success: function(result) {
            if(result.code == 200){

                var pageCount = result.data.totalPage;
                //生成分页按钮
                if(pageCount>5){
                    page_icon(1,5,0,pageCount);
                }else{
                    page_icon(1,pageCount,0,pageCount);
                }
            }else{
                parent.layer.msg(result.message);
                return false;
            }
        }
    });
    //套餐列表 不分页
    list_value();
});
function list_value(page){
    if(!page){
        //获取套餐列表  不分页
        $.ajax({
            url: ApiUrl + "/taocang?limit="+Page,
            type: 'get',
            dataType: 'JSON',
            success: function(result) {
                if(result.code == 200){
                    var html='';
                    $.each(result.data.list, function(k, v) {
                        html+='<tr>'
                            +'<td>'+v.id+'</td>'
                            +'<td>'+v.title+'</td>'
                            +'<td>'+v.type+'</td>'
                            +'<td>'+v.vector+'</td>'
                            +'<td>'+v.discount+'</td>';
                        html+='<td>'+v.goods_name_arr+'</td>'
                            +'<td>'+v.status+'</td>'
                            +'<td>'+v.created_at+'</td>'
                          /*  +'<td><a title = "编辑套餐"  href="taocang_edit.html?id='+v.id+'" class="btn btn-primary btn-circle"><i class="fa fa-list"></i></a>'
                            +'<td><a title = "删除套餐"  href="taocang_edit.html?id='+v.id+'" class="btn btn-primary btn-circle"><i class="fa fa-list"></i></a>'*/;
                    });
                    $("#value").html(html);
                }else{
                    parent.layer.msg(result.message);
                    return false;
                }
            }
        });
    }else{
        //$("#value").empty();
        //套餐列表
        $.ajax({
            url: ApiUrl + "/taocang?limit="+Page+"&page="+page,
            type: 'get',
            dataType: 'JSON',
            success: function(result) {
                if(result.code == 200){
                    var html='';
                    $.each(result.data.list, function(k, v) {
                        html+='<tr>'
                            +'<td>'+v.id+'</td>'
                            +'<td>'+v.title+'</td>'
                            +'<td>'+v.type+'</td>'
                            +'<td>'+v.vector+'</td>'
                            +'<td>'+v.discount+'</td>';
                        html+='<td>'+v.goods_name_arr+'</td>'
                            +'<td>'+v.status+'</td>'
                            +'<td>'+v.created_at+'</td>'
                          /*  +'<td><a title = "编辑分类"  href="category_edit.html?id='+v.category_id+'" class="btn btn-primary btn-circle"><i class="fa fa-list"></i></a>'*/;
                    });
                    $("#value").html(html);
                }else{
                    parent.layer.msg(result.message);
                    return false;
                }
            }
        });
    }

}